//
//  PictureBrowerViewController.swift
//  PictureBrowser
//
//  Created by kingseraphs on 28/04/2017.
//  Copyright © 2017 kingseraphs. All rights reserved.
//

import UIKit

class PictureBrowerViewController: UIViewController {

    private lazy var scrollView: UIScrollView = UIScrollView()
    let width = UIScreen.main.bounds.width
    let height = UIScreen.main.bounds.height
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        scrollView.frame = CGRect(x: 0, y: 0, width: width, height: height)
        scrollView.contentSize = CGSize(width: width * 9, height: height)
        scrollView.isPagingEnabled = true
        for i in 0..<10 {
            let imageView = UIImageView(image: UIImage(named: "image"))
            imageView.frame = CGRect(x: i * Int(width), y: 0, width: Int(width), height: Int(height))
            let doubleTap = UITapGestureRecognizer(target: self, action: #selector(self.doubleTap(sender:)))
            doubleTap.numberOfTapsRequired = 2
            doubleTap.numberOfTouchesRequired = 1
            imageView.addGestureRecognizer(doubleTap)
            imageView.isUserInteractionEnabled = true
            scrollView.addSubview(imageView)
        }
        view.addSubview(scrollView)
    }
    
    func doubleTap(sender: UITapGestureRecognizer) -> () {
        self.dismiss(animated: true, completion: nil)
    }
    
//    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
//        self.dismiss(animated: true, completion: nil)
//    }
}
